import requests
import hashlib
import json
import re
# 登录
username = 'jsh'
password = '123456'
md5 = hashlib.md5(password.encode()) # 创建MD5对象
password_md5 = md5.hexdigest()# 调用方法解密

# 请求头
headers ={
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
    'Content-Type': 'application/json;charset=UTF-8'
}
#构造url
url_base = r'http://192.168.10.226:3000'
url_login = url_base + r'/jshERP-boot/user/login'
#构造data
data_logon = {'loginName': username,'password':password_md5}
#发送请求
resp = requests.post(url_login,json=data_logon,headers=headers,verify=False)
#获取响应
token = resp.json()['data']['token']
print(token)
# patt = r'<title>(.*?)</title>'
# title = re.findall(patt, resp.text)
# print(title)
# 角色管理-新增
# name = 'yuanyuan'
# type = '全部数据'
# #构造请求头
# headers['X-Access-Token'] = token
# # #构造url
# url_role_add = url_base +r'/jshERP-boot/role/add'
# #构造data
# data_role_add = {'name':name,'type':type}
# #发送请求
# resp = requests.post(url_role_add,json=data_role_add,headers=headers,verify=False)
# #获取请求
# print(resp.text)
# 角色管理-修改
# id = 56
# name = 'yuanyuan1'
# type = '全部数据'
# #构造url地址
# url_role_mod = url_base + r'/jshERP-boot/role/update'
# #构造data
# data_role_mod = {"deleteFlag": "0", "enabled": True, "id": id, "name": name, "tenantId": 63, "type": type}
# resp = requests.put(url_role_mod, json=data_role_mod, headers=headers, verify=False)
# #获取响应
# print(resp.text)
# # 角色管理-删除
# id = 57
# #构造url
# url_role_del = url_base + r'/jshERP-boot/role/delete'
# # 构造 data
# data_role_del = {"id": id}
# # 发送请求
# resp = requests.delete(url_role_del,params=data_role_del, headers=headers,verify=False)
# #获取响应
# print(resp.text)
#角色管理-查询
# name = 'yuanyuan'
# description = ''
# #构造url
# url_role_query = url_base + r'/jshERP-boot/role/list'
# #构造data
# search_dict = {"name": name, "description": description}  # 把内层的字典单独定义
# search_str = json.dumps(search_dict)  # 把内层字典转成串
# data_role_query = {
#     'search': search_str,
#     'column': 'createTime',
#     'order': 'desc',
#     'field': ['id', '', '', 'action', 'name', 'type', 'priceLimitStr', 'description', 'sort', 'enabled'],
#     'currentPage': 1,
#     'pageSize': 10
# }
# # 发送请求
# resp = requests.get(url_role_query,params=data_role_query,headers=headers,verify=False)
# #获取响应
# print(resp.text)

# 零售出库新增
# number = 'LSCK00000000856'
# name = '口红'
# barCode = '1019'
# depotId = '18'
# #构造url
# url_retail_add = url_base + r'/jshERP-boot/depotHead/addDepotHeadAndDetail'
# # 构造data
# rows_dict = {"id":"17050308404190999733","name":name,"standard":'',"model":'',"color":'',"materialOther":"","stock":2296,"unit":"个","snList":"","batchNumber":"","expirationDate":"","sku":"","operNumber":1,"unitPrice":5,"allPrice":5,"remark":"","orderNum":1,"depotId":depotId,"barCode":barCode}
# info_dict = {"organId":78,"operTime":"2024-01-12 11:40:40","number":number,"payType":"预付款","changeAmount":"5.00","getAmount":"5.00","backAmount":0,"accountId":17,"type":"出库","subType":"零售","defaultNumber":"LSCK00000000853","totalPrice":5,"fileName":"","status":"0"}
# rows_str = json.dumps(rows_dict)
# info_str = json.dumps(info_dict)
# data_retail_add = {
#     #"info":"{\"organId\":78,\"operTime\":\"2024-01-12 11:40:40\",\"number\":\"LSCK00000000854\",\"payType\":\"预付款\",\"changeAmount\":\"5.00\",\"getAmount\":\"5.00\",\"backAmount\":0,\"accountId\":17,\"type\":\"出库\",\"subType\":\"零售\",\"defaultNumber\":\"LSCK00000000853\",\"totalPrice\":5,\"fileName\":\"\",\"status\":\"0\"}",
#     "info": info_str,
#     #"rows": rows_str
#     "rows":"[{\"id\":\"17050308404190999733\",\"name\":\"面膜\",\"standard\":null,\"model\":null,\"color\":null,\"materialOther\":\"\",\"stock\":2296,\"unit\":\"个\",\"snList\":\"\",\"batchNumber\":\"\",\"expirationDate\":\"\",\"sku\":\"\",\"operNumber\":1,\"unitPrice\":5,\"allPrice\":5,\"remark\":\"\",\"orderNum\":1,\"depotId\":\"19\",\"barCode\":\"1020\"}]"
# }
# # 发送请求
# resp = requests.post(url_retail_add,json=data_retail_add,headers=headers,verify=False)
# #获取响应
# print(resp.text)
# 零售出库——修改
# organName = '12312666'
# payType = '现付'
# #构造url
# url_retail_mod = url_base + r'/jshERP-boot/depotHead/updateDepotHeadAndDetail'
# #构造data
# info_dict ={"id":5037,"type":"出库","subType":"零售","defaultNumber":"LSCK00000000855","number":"LSCK00000000855","createTime":"2024-01-12T04:17:05.000+0000","operTime":"2024-01-12 11:40:40","organId":78,"creator":63,"accountId":17,"changeAmount":"25.00","backAmount":0,"totalPrice":25,"payType":payType,"billType":"","remark":"","fileName":"","salesMan":"","accountIdList":"","accountMoneyList":"","discount":"","discountMoney":"","discountLastMoney":0,"otherMoney":"","deposit":0,"status":"0","purchaseStatus":"0","source":"0","linkNumber":"","tenantId":63,"deleteFlag":"0","projectName":"","organName":organName,"userName":"","accountName":"账户1","allocationProjectName":"","materialsList":"面膜  ","salesManStr":"","operTimeStr":"2024-01-12 11:40:40","finishDebt":"","depotHeadType":"零售出库","creatorName":"测试用户","contacts":"小吴","telephone":"","address":"","finishDeposit":"","needDebt":"","debt":-5,"materialCount":"","hasFinancialFlag":False,"hasBackFlag":False,"realNeedDebt":"","getAmount":"25.00"}
# info_str = json.dumps(info_dict)
# data_retail_mod = {
#         "info": info_str,
#         #"info":{"id":5037,"type":"出库","subType":"零售","defaultNumber":"LSCK00000000855","number":"LSCK00000000855","createTime":"2024-01-12T04:17:05.000+0000","operTime":"2024-01-12 11:40:40","organId":78,"creator":63,"accountId":17,"changeAmount":"25.00","backAmount":0,"totalPrice":25,"payType":"现付","billType":"","remark":"","fileName":"","salesMan":"","accountIdList":"","accountMoneyList":"","discount":"","discountMoney":"","discountLastMoney":0,"otherMoney":"","deposit":0,"status":"0","purchaseStatus":"0","source":"0","linkNumber":"","tenantId":63,"deleteFlag":"0","projectName":"","organName":"10086","userName":"","accountName":"账户1","allocationProjectName":"","materialsList":"面膜  ","salesManStr":"","operTimeStr":"2024-01-12 11:40:40","finishDebt":"","depotHeadType":"零售出库","creatorName":"测试用户","contacts":"小吴","telephone":"","address":"","finishDeposit":"","needDebt":"","debt":-5,"materialCount":"","hasFinancialFlag":False,"hasBackFlag":False,"realNeedDebt":"","getAmount":"25.00"},
#         #"rows": rows1_str
#         "rows":"[{\"id\":\"7871\",\"name\":\"面膜\",\"standard\":\"\",\"model\":\"\",\"color\":\"\",\"materialOther\":\"\",\"stock\":\"2288\",\"unit\":\"个\",\"snList\":\"\",\"batchNumber\":\"\",\"expirationDate\":\"\",\"sku\":\"\",\"operNumber\":\"5\",\"unitPrice\":\"5\",\"allPrice\":\"25\",\"remark\":\"\",\"orderNum\":1,\"depotId\":\"19\",\"barCode\":\"1020\"}]"}
# # 发送请求
# resp = requests.put(url_retail_mod,json=data_retail_mod,headers=headers,verify=False)
# #获取响应
# print(resp.text)

#零售出库-删除
# id = 4790
# #构造url
# url_retail_del = url_base + r'/jshERP-boot/depotHead/delete'
# #构造data
# data_retail_del = {'id': id}
# # 发送请求
# resp = requests.delete(url_retail_del,params=data_retail_del,headers=headers,verify=False)
# #获取响应
# print(resp.text)

#零售出库查询
# materialParam = '面膜'
# #构造url
# url_retail_query = url_base + r'/jshERP-boot/depotHead/list'
# #构造data
# search_dict = {"number":'',"materialParam":materialParam,"type":"出库","subType":"零售","roleType":'全部数据',"organId":"","depotId":"","creator":"","accountId":"","status":"","remark":""}
# search_str = json.dumps(search_dict)
# data_retail_query = {
#         'search': search_str,
#         'column': 'createTime',
#         'order': 'desc',
#         'field': ['id','','action','organName','number','materialsList','operTimeStr','userName','materialCount','totalPrice','getAmount','backAmount','status'],
#         'currentPage': 1,
#         'pageSize': 10
# }
# # 发送请求
# resp = requests.get(url_retail_query,params=data_retail_query,headers=headers,verify=False)
# #获取响应
# print(resp.text)















































